package at.fhj.swd10.eshop.domain;

import java.io.Serializable;
import java.util.Date;

/**
 * @author David
 */
public class Product implements Serializable, Comparable<Product> {

    private int id;
    private Category category;
    private Label label;
    private String name;
    private String description;
    private String size;
    private Float price;
    private Date addToShopDate;
    private String image;

    public Product() {
    }

    public Product(Category category, Label label, String name, String description, String size, Float price, Date addToShopDate) {
        this.category = category;
        this.label = label;
        this.name = name;
        this.description = description;
        this.size = size;
        this.price = price;
        this.addToShopDate = addToShopDate;
    }

    public Product(Category category, Label label, String name, String description, String size, Float price, Date addToShopDate, String image) {
        this.category = category;
        this.label = label;
        this.name = name;
        this.description = description;
        this.size = size;
        this.price = price;
        this.addToShopDate = addToShopDate;
        this.image = image;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public Label getLabel() {
        return label;
    }

    public void setLabel(Label label) {
        this.label = label;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public Date getAddToShopDate() {
        return addToShopDate;
    }

    public void setAddToShopDate(Date addToShopDate) {
        this.addToShopDate = addToShopDate;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    @Override
    public boolean equals(Object o) {
        Product product = (Product) o;
        return this.id == product.getId();
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + this.id;
        return hash;
    }

    @Override
    public int compareTo(Product p) {
        if (compareCategory(p)) {
            return Integer.compare(category.getId(), p.getCategory().getId());
        } else if (compareLabel(p)) {
            return Integer.compare(label.getId(), p.getLabel().getId());
        } else {
            return Integer.compare(id, p.getId());
        }
    }

    private boolean compareCategory(Product p) {
        return Integer.compare(category.getId(), p.getCategory().getId()) != 0;
    }

    private boolean compareLabel(Product p) {
        return Integer.compare(label.getId(), p.getLabel().getId()) != 0;
    }
}
